<template>
    <div>
        <ul class="menu_top_list ">
            <li @click="add()">
                <span class="iconfont icon-fanhui"></span>

            </li>
            <li>{{ this.rbq && this.rbq.title }}</li>
            <router-link tag="li" to="/home" class="index-btn"></router-link>

        </ul>
        <div class="margin20">
            <div class="md-gamebox">
                <div class="bd cf">
                    <ul>
                        <li v-for=" (item, index) in this.list && this.list.slice(0, 8) " :key="'ifo-' + index">
                            <router-link :to="'./GameDetails?id=' + item.id">

                                <img :src="item.pic">

                                <i></i>
                            </router-link>
                            <em>{{ item.title }}</em>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="con-for">
                <van-tabs type="card" class="cf" animated v-model="active">
                    <van-tab title="最新">
                        <van-list v-model="loading" :finished="finished" finished-text="没有更多游戏了" @load="onLoad">
                            <div class="md-list">
                                <div id="list_box">

                                    <ul>
                                        <van-cell class="list-div" v-for=" (k, index) in this.con "
                                            :key="'i-fo-' + index">
                                            <li>
                                                <router-link :to="'./GameDetails?id=' + k.id">


                                                    <img :src="k.pic"><em>{{ k.title }}</em>

                                                    <p>{{ k.html5introduce }}</p><span>{{ k.category }} | 人气:{{
                                                            k.wapclicks
                                                    }}</span><i class="icon-"></i>

                                                </router-link>
                                                <router-link :to="'/start?id=' + k.id" tag="a" class="btn">开始玩
                                                </router-link>

                                            </li>
                                        </van-cell>
                                    </ul>


                                </div>
                            </div>




                        </van-list>
                    </van-tab>

                    <van-tab title="最热">
                        <van-list v-model="loading" :finished="finished" finished-text="没有更多游戏了" @load="onLoad">
                            <div class="md-list">
                                <div id="list_box">

                                    <ul>
                                        <van-cell class="list-div" v-for=" (k, index) in this.bbc "
                                            :key="'i-fo-' + index">
                                            <li>
                                                <router-link :to="'./GameDetails?id=' + k.id">


                                                    <img :src="k.pic"><em>{{ k.title }}</em>

                                                    <p>{{ k.html5introduce }}</p><span>{{ k.category }} | 人气:{{
                                                            k.wapclicks
                                                    }}</span><i class="icon-"></i>
                                                </router-link>
                                                <router-link :to="'/start?id=' + k.id" tag="a" class="btn">开始玩
                                                </router-link>

                                            </li>
                                        </van-cell>
                                    </ul>


                                </div>
                            </div>




                        </van-list>
                    </van-tab>

                </van-tabs>
            </div>

        </div>

    </div>
</template>
<script>

import { gameCont } from '@/api/home';

export default {
    data() {
        return {
            con: null,
            obj: [],
            list: [],
            rbq: null,
            bbc: null,
            loading: false,
            finished: false,
            count: 1,
            scrollTop: "",//距离顶部的距离
            scrollHeight: "",//总共的高
            offsetHeight: "",//当前页面的高.
            active: 0

        }
    },
    methods: {
        // 返回go(-1)
        add() {
            this.$router.go(-1)
        },
        gameContFun() {
            gameCont({ id: this.$route.query.id }).then(data => {

                let arr = data
                let ac = this.$route.query.id;
                // 获得下标
                let index = arr.findIndex(item => item.id == this.$route.query.id);
                this.rbq = arr[index]
                // this.obj = arr.splice(index, 1);//删除数组


                // console.log("arr", arr);
                console.log("ac", ac);
                this.list = this.rbq.data
                this.obj = this.list

                console.log(this.rbq.data);



            })
        },
        onLoad() {
            // 异步更新数据
            // setTimeout 仅做示例，真实场景中一般为 ajax 请求
            //当前高度
            this.scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop;
            //总高度
            this.scrollHeight = document.body.scrollHeight;
            //当前屏幕高度
            this.offsetHeight = document.body.offsetHeight;

            if (this.scrollTop + this.offsetHeight + 500 >= this.scrollHeight) {
                setTimeout(() => {
                    for (let i = 0; i < 2; i++) {
                        this.con = this.rbq.data.slice(0, this.count++)



                        let array = this.obj
                        let temp;
                        for (let i = 0; i < array.length / 2; i++) {
                            temp = array[i];
                            array[i] = array[array.length - 1 - i];
                            array[array.length - 1 - i] = temp;
                        }



                        this.bbc = this.list.slice(0, this.count++)
                        // console.log("con=", this.con);
                    }


                    // 加载状态结束
                    this.loading = false;

                    // 数据全部加载完成
                    if (this.con.length >= this.list.length) {
                        this.finished = true;
                    }
                }, 1000);
            }
        }


    },

    created() {
        // 获取id
        if ("id" in this.$route.query) {
            this.gameContFun()

        }

    }

}
</script>


<style lang="scss"  scoped>
.md-list li span {
    height: 18px;
    line-height: 18px;
    color: #959595;
    font-size: 11px;
}

.md-list li p {
    height: 16px;
    line-height: 16px;
    padding-right: 75px;
    color: #959595;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-list li .btn {
    position: absolute;
    top: 13.5px;
    right: 0;
    width: 64px;
    height: 12px;
    line-height: 12px;
    padding: 8px 0;
    text-align: center;
    border-radius: 5px;
    border: 1px solid #00cc7d;
    color: #00cc7d;
}

.md-list li em,
.md-list li span,
.md-list li p {
    display: block;
    margin-left: 65px;
}

.md-list li em {
    display: inline-block;
    margin-left: 10px;
    height: 18px;
    line-height: 18px;
    font-size: 14px;
    padding-right: 75px;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}



em,
i {
    font-style: normal;
    vertical-align: top;
}

.md-list li {
    position: relative;
    margin: 3px 0 15px;
    background: #fff;
    height: 55px;

    margin-bottom: 17px;
}

.list-head {
    padding: 5px 10px;
    margin-bottom: 0;
    background-color: #f5f5f5 !important;
    margin-bottom: 15px;
    height: 19px;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 15px;

}

.md-list li a:first-child {
    height: 55px;
}

.md-list li a {
    display: block;
    position: relative;
}

.md-list li img {
    float: left;
    width: 55px;
    height: 55px;
    border-radius: 12px;
}

::v-deep .van-tabs__wrap {
    height: 27px;
    line-height: 27px;
    border-radius: 5px
}

::v-deep .van-tabs__nav--card {
    height: 27px;
    line-height: 27px;
    margin: 0;
    width: 110px;
    border: 1px solid #00cc7d;

    border-radius: 5px
}

::v-deep .van-tabs__nav--card .van-tab.van-tab--active {
    background-color: #00cc7d;

}

::v-deep .van-tab--active {
    height: 27px;
    line-height: 27px;
    margin: 0;
    width: 110px;
    border: 1px solid #00cc7d;
    border-radius: 5px;
    background-color: #00cc7d;

}



::v-deep .van-tab {
    color: #00cc7d;
    border-right: 1px solid #fff;

}


.md-gamebox li:nth-child(4n) {
    margin-right: 0;
}

.md-gamebox li img {
    width: 62px;
    height: 62px;
    border-radius: 10px;
    display: block;
    margin: 0 auto;
}

.md-gamebox li em {
    line-height: 1.4;
    margin-top: 5px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    word-break: break-all;
    -webkit-line-clamp: 2;
    text-overflow: ellipsis;
    overflow: hidden;
    font-size: 14px;
}

.md-gamebox li a {
    display: block;
    width: 62px;
    height: 62px;
    position: relative;
    margin: 0 auto;
}

.md-gamebox li {
    float: left;
    width: 62px;
    margin-top: 10px;
    text-align: left;
    margin-right: 35.5px;
    position: relative;
}

.md-gamebox ul {
    display: flex;
    flex-wrap: wrap;
}

.md-gamebox .hd .more,
.md-card4 .hd .more {
    float: right;
    font-size: 13px;
    color: #959595;
    margin-top: 5px;
    height: 15px;
    line-height: 15px;
    padding-right: 10px;
    background: url("https://h.4399.com/images/2022/arrow.png") no-repeat right -0.5px;
    background-size: 9px 14px;
}

.md-gamebox .hd .title {
    color: #333333;
    font-weight: bold;
    font-size: 16px;
    float: left;
    height: 20px;
    line-height: 20px;
}


.md-gamebox .hd {
    overflow: hidden;
}

.md-gamebox {
    width: 100%;
}

.md-gamebox {

    margin-top: 48px;
}

.md-gamebox .hd .title {
    color: #333333;
    font-weight: bold;
    font-size: 16px;
    float: left;
    height: 20px;
    line-height: 20px;
}


.md-gamebox .hd {
    overflow: hidden;
}

.md-gamebox {
    width: 100%;
}

.md-gamebox {
    margin-bottom: 30px;
}

@media screen and (min-width: 601px) {
    .md-gamebox5 li {
        width: 25%;
        text-align: center;
        margin-bottom: .2rem;
        margin-right: 0;
    }

    .md-gamebox li {
        width: 25%;
        text-align: center;
        margin-bottom: .2rem;
        margin-right: 0;
    }
}

.loadmore p span {
    position: absolute;
    top: 0;
    left: 50%;
    margin-left: -60px;
    display: block;
    width: 120px;
    background: #fff;
}

.loadmore p::before {
    display: block;
    position: absolute;
    top: 16px;
    left: 50%;
    width: 250px;
    margin-left: -125px;
    height: 1px;
    background-image: linear-gradient(to right, #f1f1f1 0%, #d7d7d7 50%, #f1f1f1 100%);
    content: "";
}

.loadmore p {
    text-align: center;
    color: #959595;
    font-size: 14px;
    position: relative;
    height: 32px;
}

.loadmore {
    height: 32px;
    line-height: 32px;
    background: #fff;
    text-align: center;
}

.loadmore {
    height: 32px;
    line-height: 32px;
    text-align: center;
    margin: 20px 0;
    color: #b4b3b3;
}

.md-collect li a::after {
    content: '';
    width: 100%;
    height: 105px;
    position: absolute;
    left: 0;
    bottom: 0;
    background: url("https://h.4399.com/images/2022/dark_mask.png") repeat-x;
    background-size: 50px 200px;
}

.md-collect li span {
    position: absolute;
    right: 10px;
    bottom: 10px;
    color: #f1f1f1;
    background: url("https://h.4399.com/images/2022/eyes_icon_2.png") no-repeat left center;
    background-size: 17px 11px;
    padding-left: 19px;
    z-index: 2;
    opacity: 0.8;
}

.md-collect li p {
    width: 70%;
}

.md-collect li p {
    padding: 9px 12px;
    color: #fff;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 2;
    position: absolute;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
}

.md-collect li img {
    width: 100%;
    height: 170px;
    display: block;
}

.md-collect li a {
    display: block;
    width: 100%;
    height: 170px;
}

.md-collect li {
    margin: 0 auto 11px;
    width: 100%;
    height: 170px;
    overflow: hidden;
    position: relative;
    border-radius: 12px;
}

.md-collect {
    margin: 48px 10px;
}

.md-con-fixed {
    height: 48px;
}

.con-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 48px;
    line-height: 48px;
    background: #fff;
    color: #333333;
    z-index: 99;
}

.con-header em {
    display: block;
    height: 48px;
    text-align: center;
    font-size: 16px;
    font-weight: bold;
}

.margin20 {
    margin: 0 10px;
}

em,
i {
    font-style: normal;
    vertical-align: top;
}

.index-btn {
    background: url("https://h.4399.com/images/2022/backindex_icon.png") no-repeat -9px 0;
    background-size: 28px;
    width: 40px;
    height: 38px;
    right: 0;
    background-position: 5px 14px;
    cursor: pointer;
}

.menu_top_list {
    max-width: 500px;
    margin: 0 auto;
    position: fixed;
    height: 48px;
    width: 100%;
    background-color: white;
    color: #333;
    font-size: 16px;
    font-weight: bold;

    z-index: 90;
    top: 0;
}

.menu_top_list li+li {
    width: 64%;
    -webkit-box-pack: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.menu_top_list li {
    float: left;
    display: -webkit-box;
    -webkit-box-align: center;
    height: 48px;
}

.menu_top_list li:first-child {
    cursor: pointer;
    width: 18%;
    color: #BFBFBF;
    font-size: 20px
}

.menu_top_list li:last-child {
    width: 18%;
}

.menu_top_list li:first-child::before {
    background: url("https://rs.sfacg.com/web/m/images/menu_top_icon.png") no-repeat -49.216px 9.96px;
    background-size: 105.462px;
    content: "";
    height: 46.8px;
    width: 24.608px;
    display: block;
}
</style>